<?php

namespace common\validate;


class Module extends BaseValidate
{
    // 验证规则
    protected $rule = [];

    // Fields 验证场景定义
    public function sceneFields()
    {
        return $this;
    }

    // Find 验证场景定义
    public function sceneFind()
    {
        return $this->append('param', 'require')
            ->append('param.filter', 'array');
    }

    // Select 验证场景定义
    public function sceneSelect()
    {
        return $this->append('param', 'require')
            ->append('param.filter', 'array')
            ->append('param.page', 'array');
    }

    // Create 验证场景定义
    public function sceneCreate()
    {
        return $this->append('data.type', 'require|in:fixed,entity')
            ->append('data.icon', 'require|max:24')
            ->append('data.name', 'require|max:128')
            ->append('data.code', 'require|max:128')
            ->append('data.active', 'in:yes,no');
    }

    // Update 验证场景定义
    public function sceneUpdate()
    {
        return $this->append('data.id', 'require')
            ->append('data.type', 'in:fixed,entity')
            ->append('data.icon', 'max:24')
            ->append('data.name', 'max:128')
            ->append('data.code', 'max:128')
            ->append('data.active', 'in:yes,no');
    }

    // Delete 验证场景定义
    public function sceneDelete()
    {
        return $this->append('param.filter', 'require');
    }

    // GetRelationModule 验证场景定义
    public function sceneGetRelationModule()
    {
        return $this->append('module_code', 'require');
    }

    // CreateEntitySchema 验证场景定义
    public function sceneCreateEntitySchema()
    {
        return $this->append('data.type', 'eq:entity')
            ->append('data.icon', 'max:24')
            ->append('data.name', 'max:128')
            ->append('data.active', 'in:yes,no')
            ->append('data.code', 'require|max:128|regex:/^[a-z0-9\-\_]+$/');
    }

    // DeleteEntityModule 验证场景定义
    public function sceneDeleteEntityModule()
    {
        return $this->append('param.filter.module_id', 'require');
    }
}
